<?php
// +----------------------------------------------------------------------
// | Fanwe 多语商城建站系统 (Build on ThinkPHP)
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://www.fanwe.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: awfigq(67877605@qq.com)
// +----------------------------------------------------------------------

// 导航模型
define('NAME_REQUIRE',L('NAME_REQUIRE'));
define('URL_REQUIRE',L('URL_REQUIRE'));
define('KEY_REQUIRE',L('KEY_REQUIRE'));
define('KEY_EXISTS',L('KEY_EXISTS'));

class SiteModel extends CommonModel {
	public $_validate	=	array(
		array('name','require',NAME_REQUIRE),
		array('site_key','require',KEY_REQUIRE),
		array('site_key','checkKey',KEY_EXISTS,0,'callback'),
		array('url','require',URL_REQUIRE),
	);

	public $_auto		=	array(
		array('status','1'),  // 新增的时候把status字段设置为1
	);
	
	public function checkKey($key)
	{
		$id = intval($_REQUEST['id']);
		
		if($id > 0)
			$where['id'] = array("neq",$id);
		
		$where['site_key'] = $key;
		
		$count = $this->where($where)->count();
		
		if($count > 0)
			return false;
		else
			return true;
	}
}
?>